<?php
/**
 * Created by PhpStorm.
 * User: PanChaoZhi
 * Date: 2017/1/21
 * Time: 23:30
 */
session_start();
$productid = intval($_POST['productid']);
$userid = $_SESSION['login_id'];

try {
    $pdo = new PDO('mysql:host=localhost;dbname=shopimooc', 'root', 'localhost', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    $pdo->query("set names utf8");
    $sql = "DELETE FROM imooc_cart WHERE pro_id=? and user_id=?";
    $stmt = $pdo->prepare($sql);
    $stmt->execute(array($productid, $userid));
    $rows = $stmt->rowCount();

    if ($rows) {
        $response = [
            'errno' => 0,
            'errmsg' => 'success',
            'data' => true,
        ];
    } else {
        $response = [
            'errno' => 1,
            'errmsg' => 'fail',
            'data' => false,
        ];
    }

    echo json_encode($response);
} catch (PDOException $e) {
    echo $e->getMessage();
}